/*
A Changer
control_E
title_E
trigger_E
score_E

zone_E

cap_active_E

*/


while {true} do {
sleep dure_cap;

//////////////////// ACTIF //////////////////////////////////////////////////////////////
if (control_D == 1) then { // Zone D ATT 
cap_active_E = true;
_type = getMarkerType "title_E"; if (_type != "selector_selectedMission") then {"title_E" setMarkerType "selector_selectedMission"};
};
////////////////////////////////////////////////////////////////////////////////////////

//////////////////// BLOQUER //////////////////////////////////////////////////////////
if (control_D == 0) then { // Zone D neutre
cap_active_E = false;
_type = getMarkerType "title_E"; if (_type != "selector_selectable") then {"title_E" setMarkerType "selector_selectable"};
};
////////////////////////////////////////////////////////////////////////////////////////

//////////////////// VERROUILLER ///////////////////////////////////////////////////////
if ((control_D == -1) && (control_E == -1))  then { // D et E DEF => verrouiller par DEF
cap_active_E = false;
score_E = -100;
_color = getMarkerColor "zone_E"; if (_color != "ColorRed") then {"zone_E" setMarkerColor "colorRed"};
_color = getMarkerColor "title_E"; if (_color != "ColorRed") then {"title_E" setMarkerColor "colorRed"};
_type = getMarkerType "title_E"; if (_type != "mil_box") then {"title_E" setMarkerType "mil_box"};
};
////////////////////////////////////////////////////////////////////////////////////////

//////////////////// BLEED /////////////////////////////////////////////////////////////
if (control_E == 1) then { // Zone E sous control ATT
cap_active_E = true;
ticket_def = ticket_def - dure_cap;
if (ticket_def <= 0) then {def_lose = true};
_type = getMarkerType "title_E"; if (_type != "FireMission") then {"title_E" setMarkerType "FireMission"};
};
////////////////////////////////////////////////////////////////////////////////////////



//////////////////// Script Cap /////////////////////////////////////////////////////////////
if (cap_active_E) then {

	// Qui controle ?
	
	// Zone Neutre
	if (control_E == 0) then {
		if (score_E == 100) then {control_E = 1; "title_E" setMarkerColor "ColorBlue"}; // zone cap par Att
		if (score_E == -100) then {control_E = -1; "title_E" setMarkerColor "ColorRed"}; // zone cap par Def
	};
	
	// Zone capé
	if ((control_E == 1) && (score_E <= 0)) then {control_E = 0; "title_E" setMarkerColor "ColorBlack"}; // zone perdu par ATT, devient neutre
	if ((control_E == -1) && (score_E >= 0)) then {control_E = 0; "title_E" setMarkerColor "ColorBlack"}; // zone perdu par DEF, devient neutre
	

	
	// CAP
	
	// Att > Def
	if (score_E < 100) then {
		if ((att_side countside list trigger_E) > (def_side countside list trigger_E)) then {
			_nb_att = ((att_side countside list trigger_E) - (def_side countside list trigger_E));
			score_E = score_E + _nb_att;
			if (score_E > 100) then {score_E = 100}; // on ne dépasse pas 100
		};
	};
	
	// Def > Att
	if (score_E > -100) then {
		if ((def_side countside list trigger_E) > (att_side countside list trigger_E)) then {
			_nb_def = ((def_side countside list trigger_E) - (att_side countside list trigger_E));
			score_E = score_E - _nb_def;
			if (score_E < -100) then {score_E = -100}; // on ne dépasse pas -100
		};
	};
	
	
	
	// Couleur markeur 
	if (score_E < 0) then {  // zone cap par DEF
		_alpha = score_E / -200;  
		"zone_E" setMarkerAlpha _alpha; 
		"zone_E" setMarkerColor "ColorRed"
	};
			
	if (score_E > 0) then {  // zone cap par ATT
		_alpha = score_E / 200;  
		"zone_E" setMarkerAlpha _alpha; 
		"zone_E" setMarkerColor "ColorBlue"
	};
	
	if (score_E == 0) then {  // Neutre invisible.
	"zone_E" setMarkerAlpha 0;
	"title_E" setMarkerColor "ColorBlack";
	};

	
}; 


};